package models

import (
    "time"

    "gorm.io/datatypes"
    "gorm.io/gorm"
)

// VehicleInfo 车辆信息模型
type VehicleInfo struct {
	ID              uint           `json:"id" gorm:"primaryKey;autoIncrement"`
    VehicleCategory string         `json:"vehicle_category" gorm:"type:enum('hybrid_electric','suv_crossovers','performance','people_movers');index;comment:车辆分类"`
    VehicleType     string         `json:"vehicle_type" gorm:"type:varchar(50);index;comment:具体车辆类型"`
    FordGroup       string         `json:"ford_group" gorm:"type:varchar(50);index;comment:官网分组(如: small, fv, coming_soon)"`
    Make            string         `json:"make" gorm:"type:varchar(50);default:'Ford';uniqueIndex:uk_make_model_variant;comment:品牌"`
    Model           string         `json:"model" gorm:"type:varchar(100);not null;uniqueIndex:uk_make_model_variant;index;comment:车型"`
    Variant         string         `json:"variant" gorm:"type:varchar(100);uniqueIndex:uk_make_model_variant;comment:变体/配置"`
	PriceFrom       *float64       `json:"price_from" gorm:"type:decimal(10,2);comment:起始价格"`
	PriceTo         *float64       `json:"price_to" gorm:"type:decimal(10,2);comment:最高价格"`
	FuelType        string         `json:"fuel_type" gorm:"type:varchar(50);comment:燃料类型"`
	EngineSize      string         `json:"engine_size" gorm:"type:varchar(20);comment:发动机排量"`
	Transmission    string         `json:"transmission" gorm:"type:varchar(50);comment:变速箱类型"`
	BodyStyle       string         `json:"body_style" gorm:"type:varchar(50);comment:车身样式"`
	Doors           *int           `json:"doors" gorm:"comment:车门数量"`
	Seats           *int           `json:"seats" gorm:"comment:座位数量"`
    ImageURL        string         `json:"image_url" gorm:"type:text;comment:车辆图片URL"`
	DetailURL       string         `json:"detail_url" gorm:"type:text;comment:详情页面URL"`
	TrimDetailLink  string         `json:"trim_detail_link" gorm:"type:varchar(255);comment:车型配置详细页面链接"`
    Description     string         `json:"description" gorm:"type:text;comment:车辆描述"`
    Specifications  datatypes.JSON `json:"specifications" gorm:"type:json;comment:技术规格(JSON格式)"`
    Features        datatypes.JSON `json:"features" gorm:"type:json;comment:车辆特性(JSON格式)"`
    Availability    string         `json:"availability" gorm:"type:varchar(50);index;comment:可用性状态(例如: available, coming_soon)"`
	SourcePage      string         `json:"source_page" gorm:"type:varchar(200);comment:抓取来源页面"`
	CreatedAt       time.Time      `json:"created_at" gorm:"autoCreateTime;comment:创建时间"`
	UpdatedAt       time.Time      `json:"updated_at" gorm:"autoUpdateTime;comment:更新时间"`
	ScrapedAt       time.Time      `json:"scraped_at" gorm:"column:scraped_at;comment:抓取时间"`
	DeletedAt       gorm.DeletedAt `json:"-" gorm:"index"`
}

// TableName 指定表名
func (VehicleInfo) TableName() string {
	return "make_info_uk"
}

// VehicleResponse API响应结构
type VehicleResponse struct {
	Code    int           `json:"code"`
	Message string        `json:"message"`
	Data    []VehicleInfo `json:"data"`
	Total   int64         `json:"total"`
}

// VehicleFilter 车辆筛选参数
type VehicleFilter struct {
	VehicleCategory string  `form:"vehicle_category" json:"vehicle_category"`
	VehicleType     string  `form:"vehicle_type" json:"vehicle_type"`
    FordGroup       string  `form:"ford_group" json:"ford_group"`
	Make            string  `form:"make" json:"make"`
	Model           string  `form:"model" json:"model"`
	MinPrice        float64 `form:"min_price" json:"min_price"`
	MaxPrice        float64 `form:"max_price" json:"max_price"`
	FuelType        string  `form:"fuel_type" json:"fuel_type"`
	Page            int     `form:"page" json:"page"`
	PageSize        int     `form:"page_size" json:"page_size"`
}

// CategoryInfo Ford分类信息
type CategoryInfo struct {
	Category      string `json:"category"`
	DisplayName   string `json:"display_name"`
	ExpectedCount int    `json:"expected_count"`
	Description   string `json:"description"`
}

// GetFordCategories 获取Ford车辆分类信息
func GetFordCategories() []CategoryInfo {
	return []CategoryInfo{
		{
			Category:      "hybrid_electric",
			DisplayName:   "Hybrid & Electric",
			ExpectedCount: 9,
			Description:   "环保节能的混合动力和纯电动车型",
		},
		{
			Category:      "suv_crossovers",
			DisplayName:   "SUV & Crossovers",
			ExpectedCount: 6,
			Description:   "运动型多用途车和跨界车型",
		},
		{
			Category:      "performance",
			DisplayName:   "Performance",
			ExpectedCount: 6,
			Description:   "高性能运动车型",
		},
		{
			Category:      "people_movers",
			DisplayName:   "People Movers",
			ExpectedCount: 4,
			Description:   "多人座家庭用车",
		},
	}
}
